<style scoped>
  .Supplement{
    width: 410px;
    height: 180px;
    position: absolute;
    /* top: 43%;
    left: 28%; */
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    background: white;
    z-index: 100;
    box-shadow: 0 3px 3px 3px #e7e4e4;
  }
  .Sup_1{
    width: 100%;
    height: 40px;
    background: #f4f4f4;
    display: flex;
    justify-content: space-between;
    padding: 10px 15px;
  }
  .Sup_1 p{
    font-weight: 700;
  }
  .Sup_2{
    margin: 10px 15px;
  }
  .Sup_3{
    margin: 10px 0 0 255px;
  }

</style>

<style>
  .Supplement .el-input__inner{
    height: 30px;
    margin-left: 15px;
  }
</style>

<template>
  <div class="Supplement">
    <div class="Sup_1">
      <p>验证密码</p>
      <i @click="closepwd" class="el-icon-close"></i>
    </div>
    <p class="Sup_2">请输入{{typeStr}}密码</p>
    <el-input type="password" v-model="input" style="width:370px" @keyup.enter.native="showRevision" clearable></el-input>
    <el-button @click="closepwd" class="Sup_3">取消</el-button>
    <el-button @click="showRevision" type="primary">确定</el-button>
  </div>
</template>

<script>
import cookieFn from '../components/mixins/cookieFn'

export default {
  mixins: [cookieFn],
  props: {
    // 密码类型
    operationType: {
      type: Number,
      value: 0
    },
    // 是否确认
    isConfirm: {
      type: Boolean,
      value: true
    }
  },
  created(){
    // console.log(this.operationType)
    // if (!this.operationType) {
    //   this.operationType = 2
    // }
    switch (this.operationType) {
      case 1:
        this.typeStr = '补单'
        break;
      case 2:
        this.typeStr = '改单'
        break;
      case 3:
        this.typeStr = '删单'
        break;
      default:
        break;
    }
  },
    data(){
        return{
          // 未确认改删密码
          password: this.getCookie('jxUpdateCommand'),
          // 已确认改删密码
          delPassword: this.getCookie('jxDeleteCommand'),
          input: '',
          typeStr: '',
          principal: this.getCookie('jxPrincipal')
        }
    },
    methods:{
      closepwd(){
        this.$emit('closepwd')
        this.input = ''
        // console.log(Boolean(this.principal))
      },
      showRevision(){
        // console.log(this.password)
        // console.log(this.delPassword)
        if (!this.password) {
          this.$emit('showRevision')
          this.input = ''
          return
        }
        if (this.isConfirm) {
          // 确认了
          if(this.input == this.delPassword){
            if (!this.principal) {
              this.$message.error('非部门主管不能修改已确认单')
              return
            }
            this.$emit('showRevision')
            this.input = ''
          } else {
            this.$message.error('权限密码错误')
          }
        } else {
          if(this.input == this.password){
            this.$emit('showRevision')
            this.input = ''
          } else {
            this.$message.error('改删密码错误')
          }
        }
      }
    }
}
</script>